using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Admin.NET.Application.Entity;
using Admin.NET.Application.Entity.Business;
using Admin.NET.Application.Mqtt.mqttresponse;
using Admin.NET.Application.Service.Electricity;
using Admin.NET.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace Admin.NET.Application.Service;

/// <summary>
/// 测试服务
/// </summary>
[ApiDescriptionSettings(new string[] { "业务应用" }, Order = 200)]
[AllowAnonymous]
public class TestService : IDynamicApiController, ITransient, IPrivateDependency
{
	private readonly SqlSugarRepository<Test> _testRep;

	private readonly SqlSugarRepository<AreaBankCode> _testBank;

	private readonly SqlSugarRepository<LKLDicCode> _lkldic;

	public TestService(SqlSugarRepository<LKLDicCode> lkldic, SqlSugarRepository<Test> testRep, SqlSugarRepository<AreaBankCode> testBank)
	{
		_testRep = testRep;
		_lkldic = lkldic;
		_testBank = testBank;
	}

	/// <summary>
	/// 接口测试
	/// </summary>
	[AllowAnonymous]
	public string TestImportdata()
	{
		EPowerService ePowerService = new EPowerService();
		ePowerService.MeterUpload("241200001", 0, JsonConvert.DeserializeObject<Dictionary<string, UploadMqttInfo>>("{\"010000101224\":{\"TotalE\":null,\"Alltotal\":\"000000.1800,000000.5400,000000.0000,000000.0400,000000.7600\",\"VoltageAll\":\"eee.e,eee.e,220.3\",\"CurrentAll\":\"614.eeee,614.eeee,00.0000\",\"ActivePowerAll\":\"614.eeee,614.eeee,00.0015,00.0015\",\"SharpElectricE\":null,\"PeakElectricE\":null,\"FlatElectricE\":null,\"ValleyElectricE\":null,\"State\":\"0000\"}}")).Wait();
		return "Furion";
	}

	/// <summary>
	/// 接口测试
	/// </summary>
	[AllowAnonymous]
	public string TestImpormcc()
	{
		string[] arr = File.ReadAllLines("D:\\1\\1\\2.txt");
		string oldValue = "";
		int lineCode = 10000;
		List<LKLDicCode> dic = new List<LKLDicCode>();
		string[] array = arr;
		foreach (string line in array)
		{
			string[] info = line.Split("\t", StringSplitOptions.RemoveEmptyEntries);
			dic.Add(new LKLDicCode
			{
				Code = info[1],
				CodeName = info[2],
				TypeName = info[0],
				TypeCode = info[0],
				KindCode = 0
			});
		}
		_lkldic.InsertRange(dic);
		return "Furion";
	}

	/// <summary>
	/// 接口测试
	/// </summary>
	[AllowAnonymous]
	public string TestImportCSV()
	{
		string value = File.ReadAllText("D:\\1\\1\\1.json");
		return "Furion";
	}

	private string LowAddr(string addr)
	{
		if (addr.Length == 0 || addr.Length % 2 != 0)
		{
			return "";
		}
		List<string> arr = new List<string>();
		int slength = addr.Length / 2;
		for (int i = 0; i < slength; i++)
		{
			arr.Add(addr.Substring(i * 2, 2));
		}
		string resultvalue = "";
		for (int i = slength - 1; i >= 0; i--)
		{
			resultvalue += arr[i];
		}
		return resultvalue;
	}

	/// <summary>
	/// 增加一条数据
	/// </summary>
	/// <returns></returns>
	public async Task<bool> AddTest()
	{
		return await _testRep.InsertAsync(new Test
		{
			Name = "王五"
		});
	}

	/// <summary>
	/// 获取数据列表
	/// </summary>
	/// <returns></returns>
	[HttpGet("/test/list")]
	public async Task<List<Test>> GetTestList()
	{
		return await _testRep.GetListAsync();
	}
}
